// event_immediate.js

const EventEmitter = require('events');

class MyEmitter extends EventEmitter { }

const myEmitter = new MyEmitter();

myEmitter.on('event', (a, b) => {
    setImmediate(() => {
        console.log('异步地发生', a, b);
    });
});

myEmitter.emit('event', 'a', 'b');

for (let i = 0; i < 10; i++) {
    setTimeout(() => {
        myEmitter.emit('event', `a${i}`, `b${i}`)
    }, 100 + Math.random() * 300)
}

